from flask import Blueprint, jsonify, request, make_response

from tq.down_data import get_1991_2020_temp_data, get_1991_2020_rain_data

# 创建蓝图实例
tq_blueprint = Blueprint('tq', __name__, url_prefix='/')  # 注意这里的 url_prefix 在 app.py 中会再次被覆盖


@tq_blueprint.route("/get_1991_2020_temp_data", methods=['POST'])
def get_temp_data():
    data = request.get_json()
    station_id = data.get("station_id")
    month_list = data.get("month_list")
    print(station_id,month_list)
    if not station_id or not month_list:
        # 如果参数为空，返回错误信息
        return make_response(jsonify({'error': '缺失相关参数'}), 400)
    return get_1991_2020_temp_data(station_id, month_list)


@tq_blueprint.route("/get_1991_2020_rain_data", methods=['POST'])
def get_rain_data():
    data = request.get_json()
    station_id = data.get("station_id")
    month_list = data.get("month_list")
    if not station_id or not month_list:
        return make_response(jsonify({'error': '缺失相关参数'}), 400)
    return get_1991_2020_rain_data(station_id, month_list)